let network = require('../../utils/network.js')
var observer = require('../../libs/observer').observer;

Page(observer({
  props: {
    addrMgrStore: require('../../store/addressMgrStore.js').default
  },

  // 点击地址
  addrItemClick: function (e) {
    let addr_id = e.currentTarget.dataset.itemid;
    this.props.addrMgrStore.setActiveAddr(addr_id);
    wx.navigateBack();
  },

  // 添加地址
  addAddess: function () {
    wx.navigateTo({
      url: "/pages/address-add/index"
    });
  },

  // 编辑地址
  editAddr: function (e) {
    var itemid = e.currentTarget.dataset.itemid;
    wx.navigateTo({
      url: "/pages/address-add/index?itemid=" + itemid
    });
  },

  // 删除地址
  delAddr: function (e) {
    var itemid = e.currentTarget.dataset.itemid;
    this.props.addrMgrStore.delAddr(itemid);
  },

  // 设置默认
  setDef:function(e){
    var itemid = e.currentTarget.dataset.itemid;
    this.props.addrMgrStore.setDef(itemid);
  },

  onShow:function(){
    this.props.addrMgrStore.refreshList();
  }
}))